package com.whl.cloud.session;

import java.util.concurrent.TimeUnit;

import org.springframework.data.redis.core.RedisTemplate;

public class RedisSessionCache implements SessionCache {
	
	private RedisTemplate<String, String> redisTemplate;

	public RedisSessionCache(RedisTemplate<String, String> redisTemplate) {
		this.redisTemplate = redisTemplate;
	}

	@Override
	public void put(String key, String value, int timeout) {
		redisTemplate.opsForValue().set(key, value, timeout, TimeUnit.SECONDS);
	}

	@Override
	public String get(String key) {
		return redisTemplate.opsForValue().get(key);
	}

	@Override
	public void remove(String key) {
		redisTemplate.delete(key);

	}

	@Override
	public void expire(String key, int timeout) {
		redisTemplate.opsForValue().getOperations().expire(key, timeout, TimeUnit.SECONDS);
	}

}
